<?php

class OperationController extends AdminController
{
    public function indexAction()
    {
        $do = $this->get('do');
        switch ($do) {
            case 'list':
                $this->operation_log('行为日志');
                $parameters = array();
                $data = $this->_list('model_admin_operationlogs', $parameters);
                // 翻页
                foreach ($data['data'] as $item) {
                    $data_result[] = array(
                        'id' => $item->id,
                        'username' => $item->username,
                        'title' => $item->operation_title,
                        'uri' => $item->uri,
                        'time' => date('Y-m-d H:i:s', $item->time),
                    );
                }
                $this->ajaxresult(0, '', $data_result, array('count' => $data['count']));


                $this->operation_log('查看后台用户列表');
                $parameters['limit'] = $this->page_size;
                $page = $this->page;
                $parameters['offset'] = intval($page - 1) * $parameters['limit'];
                $parameters['conditions'] = array();
                $group_data = model_admin_users::find('all', $parameters);
                // 翻页
                $count = model_admin_users::count(array('conditions' => $parameters['conditions']));
                foreach ($group_data as $item) {
                    $data_result[] = array(
                        'id' => $item->id,
                        'username' => $item->username,
                        'email' => $item->email,
                        'group_name' => ($item->group) ? $item->group->gname : '-',
                        'truename' => $item->truename,
                        'status' => $item->status
                    );
                }
                $this->ajaxresult(0, '', $data_result, array('count' => $count));
                break;
        }
    }

    function profileAction()
    {
        $id = $this->get('id');
        $data = model_admin_operationlogs::first(array('id' => $id));
        if (!$data) $this->displayWarn('未找到您要查看的信息');
        $this->view->assign('data', $data);
    }

}
